<?php

    include_once("db_connect.php");
    include_once("include.php");

    $date = trim ($_POST['to_date_from']);
    $datet = trim ($_POST['to_date_to']);
    $time = trim ($_POST['to_time_from']);
    $timet = trim ($_POST['to_time_to']);

    if(!$date) {$date = Date("Y-m-d");}
    if(!$datet) {$datet = Date("Y-m-d");}
    if(!$time) {$time = "00:00:00";}
    if(!$timet) {$timet = "23:59:59";}

?>

<h2>Записи разговоров</h2>

<form method="post" name="op">

<table><tr><td>    
    Дата с: <input name="to_date_from" id="to_date_from" type="text" size="11" maxlength="11" value="<?=(!empty($date))?$date:Date("Y-m-d");?>">
    <a href="javascript:void(null);" id="icon2"><img src="images/calendar.gif" width="16" height="16" border=0 alt="" /></a>
    <script type="text/javascript">
	new Component.Calendar('to_date_from', {lang: 'en'});
	new Component.Calendar('to_date_from', {lang: 'en', click: 'icon2'});
    </script>
    <br>
    Время с: <input name="to_time_from" type="text" size="11" maxlength="11" value="<?=(!empty($time))?$time:"00:00:00";?>">
</td><td>
    &nbsp;&nbsp;&nbsp;&nbsp;
</td><td>
    Дата по: <input name="to_date_to" id="to_date_to" type="text" size="11" maxlength="11" value="<?=(!empty($datet))?$datet:Date("Y-m-d");?>">
    <a href="javascript:void(null);" id="icon3"><img src="images/calendar.gif" width="16" height="16" border=0 alt="" /></a>
    <script type="text/javascript">
	new Component.Calendar('to_date_to', {lang: 'en'});
	new Component.Calendar('to_date_to', {lang: 'en', click: 'icon3'});
    </script>
    <br>
    Время по: <input name="to_time_to" type="text" size="11" maxlength="11" value="<?=(!empty($timet))?$timet:"23:59:59";?>">
</td></tr></table>    
    <input type="submit" value="Найти" name="submit"><br />
</form>

<table border=1>
    <tr>
	<td>Дата</td>
	<td>Имя файла</td>
    </tr>
<?php

$logs_new = pg_exec("SELECT * FROM records WHERE record_date>='$date $time' AND record_date<='$datet $timet'");
while($t = pg_fetch_array($logs_new)){
    echo "
	<tr>
	    <td>".$t['record_date']."</td>
	    <td><a href='sound.php?id=".$t['record_id']."'>".$t['record_file_name']."</a></td>
	</tr>
    ";
}

?>
</table>
